Skip to content

Conversation

@joao-r-reis
Copy link
Contributor

@joao-r-reis joao-r-reis commented Jul 2, 2025

In #1868 we deprecated Query.WithContext and Batch.WithContext. We added ExecContext and IterContext as alternatives but we didn't add these alternatives for other ways to execute queries and batches like Query.Scan or Batch.ExecCAS.

We also didn't deprecate Query.Context() and we should have

@joao-r-reis
Copy link
Contributor Author

joao-r-reis commented Jul 2, 2025

TODO: add to changelog and rewrite commit msg

@joao-r-reis joao-r-reis requested a review from jameshartig July 2, 2025 16:44
session.go Outdated
// the applied boolean as the first argument to *Iter.Scan
func (b *Batch) ExecCAS(dest ...interface{}) (applied bool, iter *Iter, err error) {
iter = b.session.executeBatch(b, nil)
return b.ExecCASContext(nil, dest...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The context docs say:

Do not pass a nil Context, even if a function permits it. Pass context.TODO if you are unsure about which Context to use.

We should either pass a TODO or pass context.Background()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I thought about that but then the internal code that defaults to the old context field that is deprecated will not work...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe I can use context.TODO and treat context.TODO as if the user didn't provide it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I didn't make the connection with newQueryOptions and it checking for nil specifically. Could we just do q.Context() in the query ones and b.Context() in the batch ones here instead off nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I didn't think about that, yeah I'll do that

In CASSGO-22 we deprecated WithContext but we didn't deprecate Context().
IterContext and ExecContext were added as replacements but there are
other execution methods that lack a Context variant.

This patch addresses both of these issues.

Patch by João Reis; reviewed by James Hartig for CASSGO-81
@joao-r-reis joao-r-reis merged commit 61e64e6 into apache:trunk Jul 3, 2025
72 checks passed
@joao-r-reis joao-r-reis deleted the cassgo81-context branch July 3, 2025 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants